package com.android.monee.binding.adapter;

import com.android.monee.binding.Field;
import com.android.monee.binding.observable.Observable;
import com.android.monee.binding.observable.ObservableImpl;
import com.android.monee.binding.observer.Observer;
import com.android.monee.view.binding.widget.BindableTextViewDecorator;

import android.text.Editable;
import android.text.TextWatcher;

public class BindableTextViewObservableAdapter implements TextWatcher,
		Observable<BindableTextViewDecorator> {

	protected Observable<BindableTextViewDecorator> observableDelegate;

	public BindableTextViewObservableAdapter(BindableTextViewDecorator observedData) {
		this.observableDelegate = new ObservableImpl<BindableTextViewDecorator>(observedData);
		observedData.addTextChangedListener(this);
	}

	@Override
	public void afterTextChanged(Editable s) {}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count){
		observableDelegate.notify(BindableTextViewDecorator.Text.class);
	}

	public <T, V> void addObserver(Observer<BindableTextViewDecorator, T, V> o) {
		observableDelegate.addObserver(o);
	}

	public <T, V> void deleteObserver(Observer<BindableTextViewDecorator, T, V> o) {
		observableDelegate.deleteObserver(o);
	}

	public <T, V> void notify(Class<? extends Field> fieldClass) {
		observableDelegate.notify(fieldClass);
	}

	public BindableTextViewDecorator getObservedData() {
		return observableDelegate.getObservedData();
	}

}
